<?php
class ModnewsAction extends BaseAction{
    public function index(){
        
        $searchType=$_POST['searchType'];
        $searchType = $searchType==NULL?"title":$searchType;
        $keyword=$_POST['keyword'];
        import("ORG.Util.Page");
       
       if($keyword!=null){
           //总记录数
           $newsTotal=M('newsarticles')->where("{$searchType} like '%{$keyword}%'")->count();
           $page=new Page($newsTotal,6);
           $sql="select * from newsarticles a inner join newstypes b on a.typeId=b.typeId and  {$searchType} like '%{$keyword}%' limit {$page->firstRow},{$page->listRows}";
           $newsAll=M()->query($sql);
          
       }else{
           //总记录数
          $newsTotal=M('newsarticles')->count();
         // var_dump($newsTotal);exit;
          $page=new Page($newsTotal,6);
        $sql="select * from newsarticles a inner join newstypes b on a.typeId=b.typeId  limit {$page->firstRow},{$page->listRows}";
        $newsAll=M()->query($sql);
       
       }
       //分页
         
        $this->assign('xianShi',$page->show());
        $this->assign('newsAll',$newsAll);
        $this->display();
    }
   
    
}